<% /* $Id: user.jsp 101 2010-12-26 21:25:55Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="../header.jsp" %>

<%
	UserEntry userEntry = UsersModel.getUser(Long.parseLong(request.getParameter("user_id")));
	Map<String, Object> submReq = new HashMap<String, Object>();
	submReq.put("userId", userEntry.getId());
	List<SubmissionEntry> submissions = SubmissionsModel.getSubmissions(submReq);
	
	Map<String, Object> sessReq = new HashMap<String, Object>();
	sessReq.put("userId", userEntry.getId());
	sessReq.put("order", "id DESC");
	List<SessionEntry> sessions = SessionsModel.getEntries(sessReq);
	
	Map<String, Object> detailsFilter = new HashMap<String, Object>();
	detailsFilter.put("userId", userEntry.getId());
	List<SchoolOlympUserDetailsEntry> listDetails = UserDetailsModel.getEntries(detailsFilter);
	SchoolOlympUserDetailsEntry userDetails2011 = listDetails.size() > 0 ? listDetails.get(0) : null;
%>


<form action="<%= Linker.link("users") %>" method="post">
	<input type="hidden" name="id" value="<%= userEntry.getId() %>">
	<input type="hidden" name="action" value="customEdit">
	<input type="hidden" name="return" value="<%= requestUrl %>">
	<table>
		<tr>
			<th>Action</th>
			<th>Current</th>
			<th>Change</th>
		</tr>
		<tr>
			<td><%= userEntry.getLoginAllowed() ? "Disable" : "Enable" %> login</td>
			<td><%= userEntry.getLoginAllowed() %></td>
			<td><input type="submit" value="Change" name="changeLoginAllowed" /></td>
		</tr>
		<tr>
			<td>Change password</td>
			<td><input type="password" maxlength="20" name="password" /></td>
			<td><input type="submit" value="Change" name="changePassword" /></td>
		</tr>
		<tr>
			<td>Kill sessions</td>
			<td><%= sessions.size() %></td>
			<td><input type="submit" value="Change" name="killSessions" /></td>
		</tr>
<%
	if (userDetails2011 != null)
	{
		//м.Берег
%>
		<tr>
			<td>First Name</td>
			<td><input type="text" value="<%= userDetails2011.getFirstName() %>" name="firstName"></td>
			<td><input type="submit" value="Change" name="changeFirstName" /></td>
		</tr>
		<tr>
			<td>Middle Name</td>
			<td><input type="text" value="<%= userDetails2011.getMiddleName() %>" name="middleName"></td>
			<td><input type="submit" value="Change" name="changeMiddleName" /></td>
		</tr>
		<tr>
			<td>Last Name</td>
			<td><input type="text" value="<%= userDetails2011.getLastName() %>" name="lastName"></td>
			<td><input type="submit" value="Change" name="changeLastName" /></td>
		</tr>
		<tr>
			<td>Region</td>
			<td><input type="text" value="<%= userDetails2011.getRegionName() %>" name="regionName"></td>
			<td><input type="submit" value="Change" name="changeRegionName" /></td>
		</tr>
		<tr>
			<td>School</td>
			<td><input type="text" value="<%= userDetails2011.getSchoolName() %>" name="schoolName"></td>
			<td><input type="submit" value="Change" name="changeSchoolName" /></td>
		</tr>
		<tr>
			<td>Teacher</td>
			<td><input type="text" value="<%= userDetails2011.getTeacherName() %>" name="teacherName"></td>
			<td><input type="submit" value="Change" name="changeTeacherName" /></td>
		</tr>
		<tr>
			<td>Form</td>
			<td><input type="text" value="<%= userDetails2011.getFormNumber() %>" name="formNumber"></td>
			<td><input type="submit" value="Change" name="changeFormNumber" /></td>
		</tr>
<%
	}
%>
	</table>
</form>


<h2 align="center">Last submissions</h2>
<%= (new SubmissionsFormatter(SubmissionsDataFormatSettings.SHORT_IP)).format(submissions) %>

<h2 align="center">Sessions</h2>
<%= (new SessionsFormatter()).format(sessions) %>

<%@ include file="../footer.jsp" %>
